/*

This file is part of org-json.

org-json is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

using System;
using System.Collections.Generic;

namespace Org.JSON
{ 
	public class Array : Value
	{
		private List<Value> data = new List<Value>();
		
		public Array()
		{

		}
		
		public void Add(Value val)
		{
			this.data.Add(val == null ? new Null() :val);
		}
		
		public Value this[int index]
		{
			get
			{
				return this.data[index];
			}
			set
			{
				this.data[index] = value == null ? new Null() :value;
			}
		}
		
		public int Count { get { return data.Count; } }
		
		public IEnumerable<Value> AsEnumerable
		{
			get
			{
				foreach(var item in this.data)
					yield return item;
			}
		}


		public override void Serialize(Writeable output)
		{
			output.Write("[");
			
			var first = true;
			foreach(var item in this.data)
			{
				if(first)
					first = false;
				else
					output.Write(",");
				
				item.Serialize(output);
			}
			
			output.Write("]");
		}
	}
}
